package com.miukoo.aikao.core.dtos;


import com.miukoo.aikao.core.enums.ApiError;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
/**
　* @Description: ${todo}
　* @Author miukoo <miukoo@126.com>
　* @Date 2020/11/19 17:58
　* @Version 1.0
  */
@Setter
@Getter
@NoArgsConstructor
@ApiModel(value="接口响应", description="接口响应")
public class ApiResult<T>{

    /**
     * 响应消息
     */
    @ApiModelProperty(value = "响应消息")
    private String msg;
    /**
     * 响应代码
     */
    @ApiModelProperty(value = "响应代码,0为成功,1为失败", required = true)
    private Integer code;

    /**
     * 请求或响应body
     */
    @ApiModelProperty(value = "响应内容")
    protected T data;


    /**
     * 是否成功
     * @return
     */
    public boolean isSuccess(){
        return code.equals(0);
    }

    /**
     * 从结果初始化
     * @param apiResult
     */
    public ApiResult(ApiResult apiResult){
        this.code = apiResult.getCode();
        this.msg = apiResult.getMsg();
    }

    /**
     * 从枚举中获取参数
     * @param apiError
     */
    public ApiResult(ApiError apiError){
        this.code = apiError.getCode();
        this.msg = apiError.msg;
    }
}
